package leetcode.editor.cn;

import java.util.*;

public class _49_GroupAnagrams {
    public static void main(String[] args) {
        Solution solution = new _49_GroupAnagrams().new Solution();
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public List<List<String>> groupAnagrams(String[] strs) {
            Map<String, ArrayList<String>> map = new HashMap<>();
            for (int i = 0; i < strs.length; i++) {
                char[] chars = strs[i].toCharArray();
                Arrays.sort(chars);
                String key = new String(chars);
                if (!map.containsKey(key)) {
                    map.put(key, new ArrayList<>());
                }
                map.get(key).add(strs[i]);
            }
            return new ArrayList<List<String>>((map.values()));
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}